package android.kryten.activity;

import java.util.Date;
import java.util.Random;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.kryten.R;
import android.kryten.service.TopicService;
import android.kryten.service.impl.TopicServiceImpl;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

public class CreateTopicActivity extends Activity {
    /** 
     * TUTO AKTIVITU SPOUSTI CUDLIK "MENU" V AVD
     */
	
	TopicService topicService = new TopicServiceImpl();

	private EditText etName;
	private EditText etDescription;
	private Spinner spType;
	private String strSelectedType;
    private CheckBox chbIsPublic;	
    private boolean isPublic = false;
       
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_topic);
                
        spType = (Spinner) findViewById(R.id.spinner_topic_type);
	    
		spType.setOnItemSelectedListener(new OnItemSelectedListener() {
			 
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				
				switch (arg2) {
				case 1 :
					strSelectedType = "OBJECTIVE";
					break;					
				case 2 :
					strSelectedType = "DOCUMENT";
					break;
				case 3 :	
					strSelectedType = "WORKGROUP";
					break;
				default:
					strSelectedType = "OBJECTIVE";
					break;
				}							
			}
			public void onNothingSelected(AdapterView<?> arg0) {
				strSelectedType = "OBJECTIVE";
			}
			});
		
		
		chbIsPublic = (CheckBox) findViewById(R.id.chb_topic_public);
		 
		chbIsPublic.setOnClickListener(new OnClickListener() {
	 
		  public void onClick(View v) {	                
			if (((CheckBox) v).isChecked()) {
				isPublic = true;
			} else {
				isPublic = false;
			}
		  }
		});
        
        
        Button btnCreateTopic = (Button) findViewById(R.id.btn_create_topic);
        btnCreateTopic.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
				etName = (EditText)findViewById(R.id.txt_topic_field_name);
				String name = etName.getText().toString();
				
				etDescription = (EditText)findViewById(R.id.txt_topic_field_description);
				String description = etDescription.getText().toString();
				
				boolean success = topicService.createTopic(name, strSelectedType, description, isPublic);
			
				if(success){
					
				} else {
					
				}
			}
		});
        
    }
    
    
   
       
    
}